package com.zhangjingcheng.yunyixia.config;

import com.zhangjingcheng.yunyixia.properties.S3Properties;
import com.zhangjingcheng.yunyixia.util.S3UploadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class S3Config {
    @Autowired
    private S3Properties s3Properties;

    @Bean
    @ConditionalOnMissingBean
    public S3UploadUtil s3UploadUtil() {
        log.info("初始化S3UploadUtil");
        log.info("初始化S3UploadUtil，endpoint: {}", s3Properties.getEndpoint());
        return new S3UploadUtil(
                s3Properties.getEndpoint(),
                s3Properties.getAccessKey(),
                s3Properties.getSecretKey(),
                s3Properties.getBucketName(),
                s3Properties.getRegion());
    }
}